package edu.sctu.wujiayi.month06.day20150618;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * Created by user11 on 2015/6/19.
 */
public class HttpConnection {
    public static void getconnection(String path,String param) throws IOException {
        URL url = new URL(path);
        int count;
        byte[] buffer = new byte[1024];

        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setRequestMethod("POST");
        urlConnection.setDoInput(true);
        urlConnection.setDoOutput(true);
        urlConnection.setUseCaches(false);

       // urlConnection.setRequestProperty("Content-Type","text/html");

        urlConnection.connect();

        OutputStream outputStream = urlConnection.getOutputStream();
        outputStream.write(param.getBytes());
        outputStream.close();

        InputStream inputStream = urlConnection.getInputStream();

        while ((count = inputStream.read(buffer))!=-1){
            System.out.println(new String(buffer,0,count,"utf-8"));
        }
        System.out.println();
        inputStream.close();

    }
}
